using UnityEngine;
using System.Collections;

public class Application : MonoBehaviour {
	
	private static Application _instance;
	private readonly string DEBUG_TEXT_OBJECT_NAME = "DebugText(Clone)";
	
	public static Application Instance
	{
		get 
		{ 
			if( _instance == null )
			{
				_instance = FindObjectOfType(typeof(Application)) as Application;
				if (_instance == null )
					Debug.LogError("Could not locate a Application object. need play on StartScene!");
			}
			return _instance; 
		}
	}
	
	// Use this for initialization
	void Start () {
		if( _instance == null )
			_instance = this;
		
		DontDestroyOnLoad(this);
		outputDebugString("Start Scene Create!");
	}
	
	// Update is called once per frame
	void Update () {
	}
	
	public void outputDebugString(string text) {
		GameObject debugText = GameObject.Find(DEBUG_TEXT_OBJECT_NAME);
		if( debugText==null ) {
			debugText = Instantiate(Resources.Load("Prefabs/DebugText")) as GameObject;
		}
		
		GUIText guiTextComponent = debugText.GetComponent<GUIText>();
		guiTextComponent.text = "[Debug]"+text;
	}
}
